/**************************************************************
          File Name:sort.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: 2015年01月28日 10:38:40
***************************************************************/

#include<stdio.h>
#include<stdlib.h>

void bubble_sort(long n[], long count)
{
    long tmp, i, j;
    for(i=0; i<count-1; i++)
        for(j=count; j-- > i+1;)
            if(n[j] < n[j-1])     
            {
                tmp = n[j];
                n[j] = n[j-1];
                n[j-1] = tmp;
            }
}

void select_sort(long n[], long count)
{
    long i, j,small, tmp; 
    for(i=0; i<count -1; i++)
    {
        small = i;
        for(j=i+1; j<count; j++)
            if(n[small] > n[j])
                small = j;

        tmp = n[small];
        n[small] = n[i];
        n[i] = tmp;
    }
}

int main(int argc, char *argv[])
{
    long len;
    len = atol(argv[1]);
    long n[len]; 

    for(long i=0; i<len;i++)
        n[i] = rand();

    //select_sort(n, len);
    bubble_sort(n, len);
/*
    for(long i=0; i<len; i++)
        printf("%ld ", n[i]);
*/
    putchar('\n');
    return 0;
}
